跳到主要内容

BM25 二叉树的后序遍历

https://www.nowcoder.com/practice/1291064f4d5d4bdeaefbf0dd47d78541

func postorderTraversal( root *TreeNode ) []int {
result := make([]int, 0)
postorder(root, &result)
return result
}

func postorder(root *TreeNode, arr *[]int) {
if root == nil {
return
}

postorder(root.Left, arr)
postorder(root.Right, arr)
*arr = append(*arr, root.Val)
}